$(function () {
    loadNews(1)
})

function loadNews(pageNum) {
    var transactionDate = $("#transactionDate").val();
    var transactionDate1 = $("#transactionDate1").val();

    $.ajax(
        {
            url: "/record/recordList",
            dataType: "json",
            data: {transactionDate, transactionDate1, pageNum},
            success: function (result) {
                $('.page').empty()
                $("#meiyou").empty()
                // alert(result.data)
                if (result.code == "200") {
                    $('div').css('display', 'block');
                    var pageInfo = result.data
                    // $("table tr:gt(0)").remove();
                    $('table tr.shij').remove()
                    pageInfo.list.forEach((record, index) => {
                        let tr = `<tr class="shij" align="cebter">
                        <td>${record.transactionDate}</td>
                        <td>${record.amount}</td>
                        <td>${record.balance}</td>
                        <td>${record.transactionType}</td>
                        <td>${record.remark}</td>
                        </tr>`;
                        $("table").append(tr);
                    })
                    // alert(pageNum)
                    let pageSahng =
                        `
<a href="javascript:void(0)" onclick="loadNews(1)">首页</a>

<a href="javascript:void(0)" onclick="loadNews(${pageInfo.pageNum - 1})">上一页</a>
`
                    let pageXia = `

<a href="javascript:void(0)" onclick="loadNews(${pageInfo.pageNum + 1})">下一页</a>

<a href="javascript:void(0)" onclick="loadNews(${pageInfo.pages})">尾页</a>
`
                    if (pageInfo.pageNum > 1) {
                        $(".page").append(pageSahng)
                    }

                    if (pageInfo.pageNum < pageInfo.pages) {
                        $(".page").append(pageXia)
                    }
                    $(".page").append(`<p>当前是第${pageInfo.pageNum}页</p>`)
                    $(".page").append(`<p>总共有${pageInfo.pages}页</p>`)
                    $(".page").append(`<p>总共有${pageInfo.total}条数据</p>`)
                } else if(result.code == "4044") {
                    $('div').css('display', 'none');
                    $("#meiyou").append(`<h1>${result.msg}</h1>`)
                }else if(result.code == "50001" || result.code == "50002"){
                    alert(result.msg)
                }
            }
        })
    }

    function chax (){
        var transactionDate = $("#transactionDate").val();
        var transactionDate1 = $("#transactionDate1").val();
        if(transactionDate == null || transactionDate == "" || transactionDate1 == undefined){
            alert("请选择开始时间")
        }else if (transactionDate1 == null || transactionDate1 == "" || transactionDate1 == undefined){
            alert("请选择结束时间")
        }else{
            loadNews(1)
        }
    }